package com.hqyj.mall.xiaomimall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.mall.xiaomimall.entity.Items;
import com.hqyj.mall.xiaomimall.mapper.ItemsMapper;
import com.hqyj.mall.xiaomimall.service.ItemsService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service

public class ItemsServiceImpl extends ServiceImpl<ItemsMapper, Items> implements ItemsService {

    @Value("${xiaomimall.perPageSize}")
    private Integer perPageSize;

    @Resource
    private ItemsMapper itemsMapper;


    @Override
    public Items queryItemById(Integer id) {
        return super.getById(id);
    }

    @Override
    public List<Items> queryItemsListByCatalogName(String catalogName) {
        QueryWrapper<Items> queryWrapper = new QueryWrapper<Items>();
        if(!catalogName.equalsIgnoreCase("全部")){
            queryWrapper.eq("catalog",catalogName);
        }
        return super.list(queryWrapper);
    }

    @Override
    public Page<Items> queryItemsPagerByCatalogName(String catalogName,Integer currentPageNumber) {
        //传入两个参数：当前页 和 每页显示记录数
        Page<Items> page = new Page<Items>(currentPageNumber, perPageSize);
        //调用mp分页查询的方法
        //调用mp分页查询过程中，底层封装
        QueryWrapper<Items> queryWrapper = new QueryWrapper<Items>();
        if(!catalogName.equalsIgnoreCase("全部")){
            queryWrapper.eq("catalog",catalogName);
        }
        return super.page(page,queryWrapper);
    }
}
